﻿
@{
    ViewBag.Title = "登陆";
}

<link href="~/Content/Xadmin/login.css" rel="stylesheet" />
<div id="wrapper" class="login-page">
    <div id="login_form" class="form">
        <form class="register-form">
            <input type="text" placeholder="用户名" value="admin" id="r_user_name" />
            <input type="password" placeholder="密码" id="r_password" />
            <input type="text" placeholder="电子邮件" id="r_emial" />
            <button id="create">创建账户</button>
            <p class="message">已经有了一个账户? <a href="#">立刻登录</a></p>
        </form>
        <form class="login-form">
            <h2>住哪儿后台管理系统</h2><br />
            <input type="text" placeholder="用户名" id="UserName" />
            <input type="password" placeholder="密码" id="PassWord" />
            <button id="login">登　录</button>
            @*<p class="message">还没有账户? <a href="#">立刻创建</a></p>*@
        </form>
    </div>
</div>
@section scripts{
    <script type="text/javascript">
        function check_login() {
            debugger;
            var name = $("#UserName").val();
            var pass = $("#PassWord").val();


            $.ajax({
                url: '/Home/Login',
                type: 'post',
                data: {
                    UserName: name,
                    PassWord: pass,
                },
                dataType: 'json',
                success: function (res) {
                    if (res.success) {
                        $("#UserName").val("");
                        $("#PassWord").val("");
                        $(location).attr('href', '/Home/Index');
                    }
                    else {
                        $("#login_form").removeClass('shake_effect');
                        setTimeout(function () {
                            $("#login_form").addClass('shake_effect')
                        }, 1);
                    }

                }
            });
        }
        function check_register() {
            var name = $("#r_user_name").val();
            var pass = $("#r_password").val();
            var email = $("r_email").val();
            if (name != "" && pass == "" && email != "") {
                alert("注册成功！");
                $("#user_name").val("");
                $("#password").val("");
            }
            else {
                $("#login_form").removeClass('shake_effect');
                setTimeout(function () {
                    $("#login_form").addClass('shake_effect')
                }, 1);
            }
        }
        $(function () {
            $("#create").click(function () {
                check_register();
                return false;
            })
            $("#login").click(function () {
                check_login();
                return false;
            })
            $('.message a').click(function () {
                $('form').animate({
                    height: 'toggle',
                    opacity: 'toggle'
                }, 'slow');
            });
        })
    </script>
}